Page({
    data: {
        time : '' ,
        text : '' ,
        quote : '' ,
        value : '' ,
        xRepShow : false ,
        good : {
            first : -1 ,
            second : -1 ,
            third : -1
        },
        email_id : '' ,
        user_id : '' ,
        from_id : '' ,
        xButtonState : false,
        shownow: false,
        xPageReady: true
    },

    onLoad: function (opt) {
      let that = this

      that.setData({
          time : opt.time ,
          text : opt.text ,
          xPageReady: false
      })
      
  },

    xInit: async function () {
        let that = this
        await wx.cloud.callFunction({
            name: 'consulting_message',
            data: {
                action: "get_send_letter_by_id" ,
                _id: that.data.email_id
            }
        }).then(res => {
            console.log(res)
            let data = res.result[0]
            if(data.quote_info.length > 0){
                wx.cloud.callFunction({
                    name: 'evaluation_new',
                    data: {
                        action : "get_evaluates",
                        dataObj : {
                            source:1,
                            evaluation_subject_id: that.data.email_id
                        }
                    }
                }).then(res => {
                    let data = res.result[0]
                    if(res.result.length > 0){
                        that.setData({
                            xButtonState : false ,
                            shownow : true ,
                            [`good.first`] : data.understanding_score ,
                            [`good.second`] : data.heuristic ,
                            [`good.third`] : data.ease_operation ,
                            value : data.content
                        })
                    }else{
                        that.setData({
                            xButtonState : true ,
                        })
                    }
                })
            }else{
                that.setData({
                    shownow : false
                })
            }
        })

        that.setData({
            xPageReady : false
        })
    },

    xRepButton: function () {
        let that = this
        let xRepShow = that.data.xRepShow
        that.setData({
            xRepShow : !xRepShow
        })
    },

    xClose: function () {
        let that = this
        let xRepShow = that.data.xRepShow
        that.setData({
            xRepShow : !xRepShow
        })
    },

    xInput: function (e) {
        let that = this
        let value = e.detail.value
        that.setData({
            value : value
        })
    },

    xRepSubmit: function () {
        let that = this
        let value = that.data.value
        let good = that.data.good
        wx.cloud.callFunction({
            name: 'evaluation_new',
            data: {
                action: "add_evaluate",
                dataObj: {
                    source : 1,
                    evaluation_subject_id : that.data.email_id ,
                    understanding_score : good.first ,
                    heuristic : good.second ,
                    ease_operation : good.third ,
                    openid : that.data.user_id ,
                    content : value ,
                }
            }
        }).then(res => {
            that.setData({
                xRepShow : false
            })
            wx.showToast({
                title: '感谢您的评价',
                success: () => {
                    that.xInit()
                }
            })
        })
    },

    xGood: function (e) {
        let that = this
        let params = e.currentTarget.dataset
        that.setData({
            [`good.${params.key}`] : params.index
        })
        console.log(that.data.good)
    }
})